<?php
namespace Jobs\Job\Tmp;
/**
 * Class Demo
 *
 * @package     Jobs\Job\Tmp
 * @description 临时脚本示范
 *
 *              备注:
 *              1. 开发环境执行命令示范(生产环境请使用sa系统操作): /usr/bin/php /data1/htdocs/edu/jobs/job.php Jobs_Job_Tmp_Import;
 *              2. 注意内存分配情况;
 *              3. 关键信息添加日志记录或输出, 以追踪脚本执行情况;
 */
class Import extends \Base\Jobs\Job {

    public function action($argv = array()) {
        $dataTe = new \Data\Teacher\Teacher();
        $path = "/tmp/te.csv";
        $fp = fopen($path, 'r');
        while ($line = fgetcsv($fp)) {
            $data = [
                'account' => $line[0],
                'name' => $line[1],
                'subject' => 9999 + $line[3],
                'salt' => rand(10000,20000),
            ];
            $data['passwd'] = $dataTe->createPasswd(md5($data['account']), $data['salt']);
            $data['icon'] = "https://aiteimage.oss-cn-beijing.aliyuncs.com/teacher/{$data['account']}.jpg";
            $id = $dataTe->add($data);
            $degrees = explode('.', $line[2]);
            $dataTe->setDegree($id, $degrees);
        }
        $ret = $dataTe->getList();
        print_r($ret);
    }

}